package com.rover022.flixelgame.ui.equipupgrade
{
	import com.greensock.events.LoaderEvent;
	import com.rover022.flixelgame.manager.ItemManager;
	import com.rover022.flixelgame.manager.PlayerManager;
	import com.rover022.flixelgame.ui.BaseUI;
	import com.rover022.flixelgame.vo.ItemVo;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import ghostcat.ui.scroll.GScrollPanel;

	/**
	 * 通用型的 object 包裹
	 * 1 支持道具类型
	 * 2 支持英雄类型
	 * 3如果自己的UI不同就自己扩展这个类
	 * @author Administrator
	 *
	 */
	public class GeneralityPackageUI extends BaseUI
	{
		public var gridSize:int = 88;
		public var packageName:String ="EquipPackage";
		public var gridContainer:Sprite;
		public var gridDescribe:Sprite;
		public var sizeH:int = 4;
		public var gridsScrollPanel:GScrollPanel;

		public function GeneralityPackageUI()
		{
		 
		}

		override public function initUI(e:LoaderEvent = null):void
		{
			gridContainer = new Sprite();
			gridsScrollPanel = new GScrollPanel(gridContainer, true, 320, 320);
			addChild(gridsScrollPanel);
			gridDescribe = new Sprite();
			addChild(gridDescribe);
			var array:Array = PlayerManager.getInstance().getAllItems();
			for (var i:int = 0; i < array.length; i++)
			{
				var itemvo:ItemVo = array[i] as ItemVo;
				var grid:GeneralityGridUI = ItemManager.getInstance().makeGeneralityGrid(itemvo);
				addGridToContainer(array[i]);
			}
		}

		/**
		 * 丢道具入包裹
		 * @param param0
		 *
		 */
		public function addGridToContainer(param0:GeneralityGridUI, isSort:Boolean = true):void
		{
			gridContainer.addChild(param0);
		}

		/**
		 * remove道具
		 * @param param0
		 *
		 */
		public function removeGridToContainer(param0:GeneralityGridUI):void
		{
			gridContainer.addChild(param0);
		}

		/**
		 * DOTO 排序 后期加点特效
		 *
		 */
		public function sortGrid():void
		{
			var array:Array = getAllGrids();
			for (var i:int = 0; i < array.length; i++)
			{
				var item:GeneralityGridUI = array[i];
				item.x = (i % 4) * gridSize;
				item.y = int(i / 4) * gridSize;
			}
		}
		
		public function gridClick(e:MouseEvent):void
		{
			var grid:GeneralityGridUI = e.currentTarget as GeneralityGridUI;
			showGridInfo(grid.parentRef);
		}

		/**
		 * 显示格子包含的的信息
		 * @param item
		 *
		 */
		public function showGridInfo(item:*):void
		{
		}

		private function gridClick(e:MouseEvent):void
		{
			var grid:GeneralityGridUI = e.currentTarget as GeneralityGridUI;
			showGridInfo(grid.parentRef);
		}

		public function getAllGrids():Array
		{
			var array:Array = [];
			for (var i:int = 0; i < gridContainer.numChildren; i++)
			{
				array.push(gridContainer.getChildAt(i));
			}
			return array
		}
	}
}
